import instance from '@/http/index.js'

/**
 * 获取用户信息
 * @data {*} id
 */
export const getUserInfoApi = (id) => {
  return instance({
    url: '/user/getUserInfo',
    method: 'post',
    data: {
      id,
    },
  })
}

/**
 * 更改用户密码
 * 参数 @data:id,oldPassword,newPassword
 */
export const changePasswordApi = (id, oldPassword, newPassword) => {
  return instance({
    url: '/user/changePassword',
    method: 'post',
    data: {
      id,
      oldPassword,
      newPassword,
    },
  })
}

/**
 * 修改用户姓名
 * 参数 @data:id name
 */
export const changeNameApi = (id, name) => {
  return instance({
    url: '/user/changeName',
    method: 'post',
    data: {
      id,
      name,
    },
  })
}

/**
 * 修改用户性别
 * 参数 body:id,sex
 */
export const changeSexApi = (id, sex) => {
  return instance({
    url: '/user/changeSex',
    method: 'post',
    data: {
      id,
      sex,
    },
  })
}

/**
 * 修改用户邮箱
 * 参数 body:id,email
 */
export const changeEmailApi = (id, email) => {
  return instance({
    url: '/user/changeEmail',
    method: 'post',
    data: {
      id,
      email,
    },
  })
}

/**
 * 绑定账号
 * 参数 body:account, onlyId, url
 */
export const bindAccountApi = (account, onlyId, url) => {
  return instance({
    url: '/user/bindAccount',
    method: 'post',
    data: {
      account,
      onlyId,
      url,
    },
  })
}

// ----------------------------------------------------用户管理

// 添加管理员
export const createAdmin = (data) => {
  const { account, ...identity } = data
  return instance({
    url: '/user/createAdmin',
    method: 'POST',
    data: {
      account,
      ...identity,
    },
  })
}


// 获取管理员列表
export const getAdminList = identity => {
	return instance({
		url: '/user/getAdminList',
		method: 'POST',
		data: {
			identity
		}
	})
}

// 编辑管理员账号信息
export const editAdmin = data => {
	const {
		id,
		...department
	} = data
	return instance({
		url: '/user/editAdmin',
		method: 'POST',
		data: {
			id,
			...department
		}
	})
}

// 对管理员取消赋权
export const changeIdentityToUser = id => {
	return instance({
		url: '/user/changeIdentityToUser',
		method: 'POST',
		data: {
			id
		}
	})
}

// 对用户进行赋权 
export const changeIdentityToAdmin = (id, identity) => {
	return instance({
		url: '/user/changeIdentityToAdmin',
		method: 'POST',
		data: {
			id,
			identity
		}
	})
}

// 通过账号对用户搜索
export const searchUser = (account,identity) => {
	return instance({
		url: '/user/searchUser',
		method: 'POST',
		data: {
			account,
			identity
		}
	})
}

// 通过部门对用户搜索
export const searchDepartment = department => {
	return instance({
		url: '/user/searchUserByDepartment',
		method: 'POST',
		data: {
			department
		}
	})
}


// 冻结用户
export const banUser = id => {
	return instance({
		url: '/user/banUser',
		method: 'POST',
		data: {
			id
		}
	})
}

// 解冻用户
export const hotUser = id => {
	return instance({
		url: '/user/hotUser',
		method: 'POST',
		data: {
			id
		}
	})
}

// 获取冻结用户列表
export const getBanList = () => {
	return instance({
		url: '/user/getBanList',
		method: 'POST',
	})
}

// 删除用户  deleteUser
export const deleteUser = (id, account) => {
	return instance({
		url: '/user/deleteUser',
		method: 'POST',
		data: {
			id,
			account
		}
	})
}

// 获取对应身份的一个总人数
export const getAdminListLength = identity => {
	return instance({
		url: '/user/getAdminListLength',
		method: 'POST',
		data: {
			identity
		}
	})
}

// 监听换页返回数据
export const returnListData = (pager,identity) => {
	return instance({
		url: '/user/returnListData',
		method: 'POST',
		data: {
			pager,
			identity
		}
	})
}